/* @(#)GSOperatorAddConfirmAction.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-3-10     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.action;

import java.util.ArrayList;
import java.util.HashMap;

import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSOperatorProcessor;
import com.hitrust.gs.form.GSOperatorAddForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.security.Encryptor;

/**
 * 
 */
public class GSOperatorAddConfirmAction extends GSBaseAction {

    
    public String execute(GSBaseForm aForm) throws Exception {
        
        GSOperatorAddForm tForm = (GSOperatorAddForm)aForm;
        GSOperatorBean tOperBean = new GSOperatorBean();
        try{
            //取得页面传入参数封装到操作员BEAN对象
            tOperBean.setGs_oper_id(tForm.operId);
            tOperBean.setGs_oper_name(tForm.operName);
            if(!tForm.operPwd.equals(tForm.confirmPwd)){
                GSLogWriter.error(this,GSException.E10057_MSG);
                throw new GSException(GSException.E10057,GSException.E10057_MSG);
            }
            tOperBean.setGs_oper_pwd(Encryptor.encrypt(tForm.operPwd));
            //tOperBean.setGs_oper_pwd(tForm.operPwd);
            tOperBean.setGs_oper_email(tForm.email);
            tOperBean.setGs_oper_phone(tForm.contactTel);
            tOperBean.setGs_oper_position(tForm.operPostion);
            tOperBean.setGs_oper_org_id(tForm.operOrg2);
            tOperBean.setGs_oper_validity(tForm.validity);
            tOperBean.setGs_oper_sex(tForm.operSex);
            //操作员新增操作
            GSOperatorProcessor tOperProc = new GSOperatorProcessor();
            boolean tFlag = tOperProc.addOperator(tOperBean);
            if(tFlag){
                tForm.getRequest().setAttribute("message","操作员新增成功");
            }else{
                tForm.getRequest().setAttribute("message","操作员新增失败");
                throw new GSException(GSException.E10060,GSException.E10060_MSG);
            }
        }catch(Exception e){
            tForm.getRequest().setAttribute("action","A400501.do");
            throw e;
        }
        tForm.getRequest().setAttribute("message","操作员新增成功");
        aForm.getRequest().setAttribute("requery","true");
        
        //取得可查询操作员及组织之间的关系集
        GSOperatorBean tCurOper = (GSOperatorBean)aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        //将当前用户信息放入request中
        aForm.getRequest().setAttribute("curoperator",tCurOper);
        
        HashMap tMap = GSOperatorProcessor.getViewableOrgAndOperator(tCurOper);
        //取得操作员所属企业及其所有下级企业
        ArrayList tList = (ArrayList)tMap.get("organization");
        aForm.getRequest().setAttribute("Organization",tList);
        tMap.remove("organization");
        aForm.getRequest().setAttribute("OrgAndOper",tMap);
        
        //设定查询模式
        aForm.getRequest().setAttribute("querymode","Q");
        
        //查询条件
        aForm.getRequest().setAttribute("s_operOrgId",aForm.getRequest().getParameter("s_operOrgId"));
        aForm.getRequest().setAttribute("s_operId",aForm.getRequest().getParameter("s_operId"));
        aForm.getRequest().setAttribute("s_operName",aForm.getRequest().getParameter("s_operName"));
        aForm.getRequest().setAttribute("s_keyWord",aForm.getRequest().getParameter("s_keyWord"));
        
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
